#pragma once
#include <string.h>
#include <stdint.h>
#include <string>
#include <json/json.h>
using namespace std;
#define TCP_PORT 28989
#define UDP_PROT 28989
#define UDP_COUNT 10240
//双方发送的UDP数据格式
class UdpMsg
{
    public:
        UdpMsg()
        {
        }

        ~UdpMsg()
        {

        }
        //序列化---把对象转化为二进制
        //将json对象打包成一条出参的消息，此时的消息是json格式，也就是二进制的
        void Serialize(string* msg)
        {
            Json::Value json_val;
            json_val["nick_name"] = nick_name_;
            json_val["school"] = school_;
            json_val["user_id"] = user_id_;
            json_val["msg"] = msg_;
            Json::FastWriter writer;
            *msg = writer.write(json_val);
            
        }
        //反序列化----把二进制转化为对象
        void DeSerialize(string msg)
        {
            Json::Reader reader;
            Json::Value val;
            reader.parse(msg,val);
            nick_name_ = val["nick_name"].asString();
            school_ = val["school"].asString();
            user_id_ = val["user_id"].asUInt();
            msg_ = val["msg"].asString();
        }
    public:
        string nick_name_;
        string school_;
        uint32_t user_id_;
        string msg_;
};  
//注册请求的数据格式
struct RegisterInfo
{
    RegisterInfo()
    {
        memset(name,'\0',sizeof(name));
        memset(school,'\0',sizeof(school));
        memset(passwd,'\0',sizeof(passwd));
    }
    //学校、姓名、密码
    char name[20];
    char school[20];
    char passwd[20];
};

//状态
enum STATUS
{
    REGISTER = 1,
    LOGIN,
    LOGINOUT,
    EXIT
};

//登录请求的数据格式
struct LoginInfo
{
    LoginInfo()
    {
        id_ = 0; 
        memset(passwd,'\0',sizeof(passwd));
    }
    //密码
    //id
    uint32_t id_;
    char passwd[20];
};

//服务端回复客户端请求应答格式
struct ReplyInfo
{
    //自身的状态(登录状态还是注册状态)
    //返还id
    int resp_state = -1;
    uint32_t id_ = 0;
};

enum State
{
    Register_Faild = 0,
    Register_Success,
    Login_Faild,
    Login_Success,
    Login_Online
};
//如何标识当前的请求是注册还是登录
enum ResqType
{
    Register = 0,
    Login
};
string resq_type[] = 
{
    "Register_Faild",
    "Register_Success",
    "Login_Faild",
    "Login_Success"
};
